<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const obj = {
            name: 'jhy',
            stus: [
                '1',
                '2',
                '3',
                '4'
            ],
            [Symbol.iterator]() {
                let index = 0
                let _this = this
                return {
                    next: function () {
                        if (index < _this.stus.length) {
                            const result = { value: _this.stus[index], done: false }
                            index++
                            return result
                        } else {
                            return { value: undefined, done: true }
                        }
                    }
                }
            }
        }
        //iterator语法糖，对象不支持，除非自己写iterator
        for (const e of obj) {
            console.log(e);
        }
    </script>
</body>

</html>